function surfcloth(X,Y,Z,L);
axis([-length(X)/2 length(X)/2 -length(X)/2 length(X)/2 -2 2]);
hold on
%Horizontal lines
for i=1:length(X),
    for j=1:length(X)-1,
        lengthL=norm([X(i,j)-X(i,j+1) Y(i,j)-Y(i,j+1) Z(i,j)-Z(i,j+1)]);
        factor=min(1.1*(lengthL)-L,1);
        factor=max(factor,0);
        plot3([X(i,j) X(i,j+1)],[Y(i,j) Y(i,j+1)],[Z(i,j) Z(i,j+1)],'Linewidth',2,'Color',[factor 1-factor 0]);
    end
end
% Vertical lines
X=X'; Y=Y'; Z=Z';
for i=1:length(X),
    for j=1:length(X)-1,
        lengthL=norm([X(i,j)-X(i,j+1) Y(i,j)-Y(i,j+1) Z(i,j)-Z(i,j+1)]);
        factor=min(1.1*(lengthL)-L,1);
        factor=max(factor,0);
        plot3([X(i,j) X(i,j+1)],[Y(i,j) Y(i,j+1)],[Z(i,j) Z(i,j+1)],'Linewidth',2,'Color',[factor 1-factor 0]);
    end
end
%Diagonal lines1
for i=1:length(X)-1,
    for j=1:length(X)-1,
        lengthL=norm([X(i,j)-X(i+1,j+1) Y(i,j)-Y(i+1,j+1) Z(i,j)-Z(i+1,j+1)]);
        factor=min(1.1*(lengthL)-sqrt(2)*L,1);
        factor=max(factor,0);
        plot3([X(i,j) X(i+1,j+1)],[Y(i,j) Y(i+1,j+1)],[Z(i,j) Z(i+1,j+1)],'Linewidth',2,'Color',[factor 1-factor 0]);
    end
end
%Diagonal lines2
for i=2:length(X),
    for j=1:length(X)-1,
        lengthL=norm([X(i,j)-X(i-1,j+1) Y(i,j)-Y(i-1,j+1) Z(i,j)-Z(i-1,j+1)]);
        factor=min(1.1*(lengthL)-sqrt(2)*L,1);
        factor=max(factor,0);
        plot3([X(i,j) X(i-1,j+1)],[Y(i,j) Y(i-1,j+1)],[Z(i,j) Z(i-1,j+1)],'Linewidth',2,'Color',[factor 1-factor 0]);
    end
end

view(30,30);
grid on;


